<template>
  <div style="line-height: 0;">
    <div style="margin-top: 15px; margin-bottom: 15px; line-height: 0; text-align: left;">
      <el-row>
        <label style="margin-left: 10px;">申请人姓名：</label>
        <el-input style="width: 200px;" prefix-icon="el-icon-search" v-model="params.username" placeholder="请输入申请人姓名"></el-input>
          &nbsp;&nbsp;&nbsp;
        <label style="margin-left: 10px;">审核人姓名：</label>
        <el-input style="width: 200px;" prefix-icon="el-icon-search" v-model="params.checkername" placeholder="请输入审核人姓名"></el-input>
        <el-button type="warning" round style="margin-left: 10px;" @click="loadinfo">查询</el-button>
        <el-button type="warning" round style="margin-left: 10px;" @click="reset">重置</el-button>
      </el-row>
    </div>
    <div >
      <el-table
          :data="tableData"
          border
          style="width: 100%">
        <el-table-column prop="check_id" v-if="false"></el-table-column>
        <el-table-column prop="account" label="申请人账号" width="180"></el-table-column>
        <el-table-column prop="username" label="申请人名称" width="180"></el-table-column>
        <el-table-column prop="shopname" label="店铺名称" width="180"></el-table-column>
        <el-table-column prop="email" label="申请人邮箱" width="180"></el-table-column>
        <el-table-column prop="checkTime" label="审核时间" width="180"></el-table-column>
        <el-table-column prop="checkername" label="审核人名称" width="180"></el-table-column>
        <el-table-column prop="statusvalue" label="审核状态" width="180"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="primary" @click="agree(scope.row)">同意</el-button>

            <el-button type="danger" @click="reject(scope.row)">拒绝</el-button>

          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="block" style="text-align: center;">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="params.pageNum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="params.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>

  </div>

</template>
<script>
import request from "@/utils/request";

export default {
  name:'checkapplyview',
  data() {
    return {
      params: {
        username:'',
        checkername: '',
        pageNum: 1,
        pageSize: 10
      },
      user: sessionStorage.getItem("user"),
      tableData: [],
      total: 0,
      formLabelWidth: '190px',
      dialogFormVisible: false,
      form : {},
      id:'',
      status:''
    }
  },
  //在页面加载的时候，做一些事情
  created() {
    this.loadinfo();
  },
  //定义一些页面上触发事件调用的方法
  methods:{
    //页面加载数据信息
    loadinfo(){
      request.post("/user/findcheckinfo",this.params).then(res => {
        if (res.code === '0') {
          this.tableData = res.data.list;
          this.total = res.data.total;
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    reset(){
      this.params = {
        pageNum: 1,
        pageSize: 10,
        checkername:'',
        username: '',
      }
      this.loadinfo()
    },
    //同意申请
    agree(obj){
      this.id = obj.checkId;
      if (obj.statusvalue !== "未审核"){
        this.$message.warning("该申请已被审核，请勿重复审核!")
      } else {
        request.post("/user/checkagree/" + this.id,this.user).then(res => {
          if (res.code === '0') {
            this.$message.success("审核已同意通过")
            this.loadinfo();
          } else {
            this.$message.error(res.msg)
            this.loadinfo();
          }
        })
      }
    },
    //拒绝商家注册
    reject(obj){
      this.id = obj.checkId;
      if(obj.statusvalue !== "未审核") {
        this.$message.warning("该申请已被审核，请勿重复审核!")
      } else {
        request.post("/user/checkreject/" + this.id,this.user).then(res => {
          if (res.code === '0') {
            this.$message.success("审核已完成，商家注册已拒绝")
            this.loadinfo();
          } else {
            this.$message.error(res.msg)
            this.loadinfo();
          }
        })
      }
    },
    handleSizeChange(pageSize){
      this.params.pageSize = pageSize;
      this.loadinfo();
    },
    handleCurrentChange(pageNum){
      this.params.pageNum = pageNum;
      this.loadinfo();
    },
  }
}
</script>